package com.jz.digital.net;

import java.util.ArrayList;
import java.util.List;

import okhttp3.Interceptor;

public class NetConfiguration {
    private long mTimeOut;
    private String mHost;

    /**
     * 网络请求拦截器
     */
    private List<Interceptor> mRequestInterceptorList;

    /**
     * 网络拦截器
     */
    private List<Interceptor> mUrlInterceptorList;

    private NetConfiguration(long timeOut, String host, List<Interceptor> requestInterceptorList, List<Interceptor> urlInterceptorList) {
        mTimeOut = timeOut;
        mHost = host;
        mRequestInterceptorList = requestInterceptorList;
        mUrlInterceptorList = urlInterceptorList;
    }

    public long getTimeOut() {
        return mTimeOut;
    }

    public String getHost() {
        return mHost;
    }

    public List<Interceptor> getRequestInterceptorList() {
        return mRequestInterceptorList;
    }

    public List<Interceptor> getUrlInterceptorList() {
        return mUrlInterceptorList;
    }

    public static class Builder{
        /**
         * 自定义时长
         */
        public static final long CUSTOM_TIME_OUT = 15 * 1000;
        //本地服务器有时需要20s以上才能请求成功，故改为30s
        public static final long TimeOut = 30 * 1000;
        private String Host = "http://cloud.user.veryfitplus.com/";
        /**
         * 网络请求拦截器
         */
        private List<Interceptor> RequestInterceptorList;

        /**
         * 网络拦截器
         */
        private List<Interceptor> UrlInterceptorList;

        public Builder(String host) {
            Host=host;
            RequestInterceptorList=new ArrayList<>();
            UrlInterceptorList=new ArrayList<>();
        }

        public Builder RequestInterceptorList(List<Interceptor> requestInterceptorList) {
            if (requestInterceptorList!=null&&requestInterceptorList.size()>0)RequestInterceptorList.addAll(requestInterceptorList);
            return this;
        }

        public Builder UrlInterceptorList(List<Interceptor> urlInterceptorList) {
            if (urlInterceptorList!=null&&urlInterceptorList.size()>0)UrlInterceptorList.addAll(urlInterceptorList);
            return this;
        }

        public Builder addRequestInterceptorList(Interceptor requestInterceptor) {
            if (requestInterceptor!=null)RequestInterceptorList.add(requestInterceptor);
            return this;
        }

        public Builder addUrlInterceptorList(Interceptor urlInterceptor) {
            if (urlInterceptor!=null)UrlInterceptorList.add(urlInterceptor);
            return this;
        }

        public NetConfiguration build(){
            return new NetConfiguration(TimeOut,Host,RequestInterceptorList,UrlInterceptorList);
        }
    }
}
